unit FrmMain;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs,
  FireDAC.Stan.Intf, FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf,
  FireDAC.Phys.Intf, FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async,
  FireDAC.Phys, FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf,
  FireDAC.DApt, System.Rtti, Data.Bind.EngExt, Fmx.Bind.DBEngExt,
  System.Bindings.Outputs, Fmx.Bind.Editors, FMX.StdCtrls, Data.Bind.Components,
  Data.Bind.DBLinks, Fmx.Bind.DBLinks, Data.DB, Data.Bind.DBScope, FMX.Grid,
  FMX.ListBox, FMX.Layouts, FireDAC.Comp.DataSet, FireDAC.Comp.Client,
  FireDAC.Phys.TDBXBase, FireDAC.Phys.TDBX, FireDAC.Moni.Base,
  FireDAC.FMXUI.Wait, FireDAC.Comp.UI, FireDAC.FMXUI.Login,
  Data.SqlExpr, IPPeerClient, FireDAC.Phys.DataSnap, Datasnap.DBClient,
  Data.DbxDatasnap, Data.DBXCommon, Datasnap.DSConnect, IdBaseComponent,
  IdComponent, IdTCPConnection, IdTCPClient;

type
  TMain = class(TForm)
    ListBox1: TListBox;
    ListBoxGroupHeader1: TListBoxGroupHeader;
    StringGrid1: TStringGrid;
    BindSourceDB1: TBindSourceDB;
    BindingsList1: TBindingsList;
    DataSource1: TDataSource;
    BindDBGridLink1: TBindDBGridLink;
    ToolBar1: TToolBar;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    FDPhysDataSnapDriverLink1: TFDPhysDataSnapDriverLink;
    cdsView: TClientDataSet;
    SQLConnection1: TSQLConnection;
    DSProviderConnection1: TDSProviderConnection;
    IdTCPClient1: TIdTCPClient;
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure cdsViewNewRecord(DataSet: TDataSet);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Main: TMain;

implementation

{$R *.fmx}

procedure TMain.cdsViewNewRecord(DataSet: TDataSet);
begin
  with DataSet do
  begin
    FieldByName('Code_').AsString := FormatDateTime('YYMMHHmmSS', Now());
  end;
end;

procedure TMain.FormCreate(Sender: TObject);
var
  Str: String;
begin
  Self.SQLConnection1.Connected := True;
  IdTCPClient1.Connect;
  if IdTCPClient1.Connected then
  begin
    IdTCPClient1.Socket.Write(123);
    Str := IdTCPClient1.Socket.ReadString(100);
  end;
end;

procedure TMain.SpeedButton1Click(Sender: TObject);
begin
  Self.cdsView.Active := False;
  Self.cdsView.CommandText := 'select top 20 * from Part';
  Self.cdsView.Open;
end;

procedure TMain.SpeedButton2Click(Sender: TObject);
begin
  if Self.cdsView.Active then
    Self.cdsView.Append;
end;

procedure TMain.SpeedButton3Click(Sender: TObject);
begin
  if Self.cdsView.Active and (Self.cdsView.RecordCount > 0) then
    Self.cdsView.Delete;
end;

procedure TMain.SpeedButton4Click(Sender: TObject);
begin
  if Self.cdsView.Active then
    Self.cdsView.Post;
end;

end.
